<div class="row" xmlns:th="http://www.w3.org/1999/xhtml">
    <div class="col-xs-12">
        <div class="box">
            <div class="box-header">
                <h3 class="box-title">日志管理</h3>
                <div class="box-tools">
                    <div class="input-group input-group-sm" style="width: 350px;">
                        <input type="text" name="table_search" id="searchNameId"
                               class="form-control pull-right" placeholder="用户名">

                        <div class="input-group-btn">
                            <button type="button" class="btn btn-default btn-search">
                                <i class="fa fa-search"></i>
                            </button>
                            <button type="button" class="btn btn-default btn-delete">删除</button>
                            <button type="button" class="btn btn-default btn-update">修改</button>
                        </div>
                    </div>
                </div>
            </div>
            <!-- /.box-header -->
            <div class="box-body table-responsive no-padding" >
                <table class="table table-hover">
                    <thead id="theadId">
                    <tr id="theadTr">
<!--                        <th><input type="checkbox" id="checkAll">全选</th>-->
                        <th>学号</th>
                        <th>姓名</th>


                    </tr>
                    </thead>
                    <tbody id="tbodyId">
                    <tr>
                        <td colspan="7">数据正在加载中...</td>
                    </tr>
                    </tbody>
                </table>
            </div>
            <div id="pageId" class="box-footer clearfix" dm="100">

            </div>
            <!-- /.box-body -->
        </div>
        <!-- /.box -->
    </div>
</div>
<script type="text/javascript">
    $(function(){


    })
    function doGetCurrNames(classId) {
        console.log("doGetCurrNames"+classId);
        console.log($('#theadTr'));
        $.ajax({
            type:"get",
            url:"score/doGetCurrNames",
            data:classId,
            //cache:true,    //缓存
            async:false,    //表示同步   默认的是异步的true
            dataType:"JSON",//表示返回值参数类型
            success:function(result){


                var th=doCreateTheads(result);
                $('#theadTr').append(th)  ;
            }
        });
    }
    function doCreateTheads(result) {

        console.log(result.data);
        var size=Object.keys(result.data).length;
        var th;
        //表头循环 拼接 科目名称
        for (i=1;i<=size;i++){
            var a=`<th>${result.data[i-1]}</th>`;
            th=th+a;
        }
        th=th+`<th>总分</th>
               <th>总学分</th>
               <th>更新</th>`
        return th;

    }
    //表格 td
    function  dogetScoreObjects(classId){
        console.log("tb"+classId);
        $.ajax({
            type:"get",
            url:"score/findObjectByClassId",
            data:classId,
            //cache:true,    //缓存
            async:false,    //表示同步   默认的是异步的true
            dataType:"JSON",//表示返回值参数类型
            success:function(jsonresult){
               // var size=Object.keys(jsonresult.data).length
                $('#tbodyId').empty();
                //jsonresult.forEach(item=>tBody.append(doCreateRow(item)));
                $('#tbodyId').append(doCreateTbodys(jsonresult.data));//List<ScoreVo>
                $('#tbodyId').data("list",jsonresult.data);
                $('#tbodyId').data("classId",classId);
            }
        });
    }
    function doCreateTbodys(list){

        console.log("hahaha"+list);
        var size=Object.keys(list).length;//list.length
        var size1=Object.keys(list[0].currScores).length;
        console.log("size"+size);
        console.log(list[0]);
        var tbs;
        for (i=0;i<size;i++){
          var  a=`<tr>

    	          <td>${list[i].studentId}</td>
    	          <td>${list[i].studentName}</td>`;

                for(j=0;j<size1;j++){
                a=a+`<td>${list[i].currScores[j]==null?"未录入":list[i].currScores[j].score}</td>`
            };

             a= a+`<td >${list[i].totalScore}</td>
    	          <td>${list[i].totalCredit}</td>
                   <td><button type="button"  onclick=doUpdateScores(this.value) value=${list[i].studentId}>更新</button></td>
    	        </tr>`;
             tbs=tbs+a;
        }

        return tbs;
    }

    /*****************删  改*******************/
    function doUpdateScores(studentId){
        //跳转页面 带数据
        alert(studentId);
        var url="score/score_update";
        $("#mainContentId").load(url,function(){
                 doUpdateScoreById(studentId);
                 dogetParams(studentId);
        })
    }

       // var scoreVo=$('#tbodyId').data("list");
       //  var classId=$('#tbodyId').data("classId")
       //  console.log("studentId:"+item);
       //  var url="score/score_update";
       //  $("#mainContentId").load(url,function(){
       //      //$(".box-title").html(title);
       //      //$('#scoredata').data("scoreVo",scoreVo);
       //      doUpdateScoreById(scoreVo,item);
       //      dogetParams(scoreVo,item,classId);
       //  })



</script>